<?php


namespace core\lib;

/**
 * Class Config
 * @package core\lib
 */
class Config {

    /**
     * @var array
     */
    protected static $config = null;

    /**
     * 读取配置文件
     * @return array
     */
    public static function read(): array {
        return require_once __ROOT__ . "/config/config.php";
    }

    /**
     * 获取配置项
     * @param string $key
     * @return mixed
     */
    public static function get(string $key = '') {
        if (is_null(self::$config)) {
            self::$config = self::read();
        }
        if ($key === '') {
            return self::$config;
        }
        $splits = explode(".", $key);
        $p = self::$config;
        foreach ($splits as $_k) {
            if (empty($p[$_k])) {
                return null;
            }
            $p = $p[$_k];
        }
        return $p;
    }

}
